#include "stm32f10x.h"
#include "generic.h"
#include "OLED_I2C.h"
#include "Serial.h"
#include "HMC5983.h"

/*硬件接线    endcoding:UTF-8
OLED:  SCL B10   SDA B11
HMC5983:  SCL A0   SDA A1
USART(串口):  TX A9   RX A10
*/

HMC5983_Typedef HMCs5983;
int main(void)
{
    Serial_Init(USART1,115200);
    HMC5983_Init(GPIOA,GPIO_Pin_0,GPIO_Pin_1);//初始化HMC5983磁力计
    OLED_Init(GPIOB,GPIO_Pin_10,GPIO_Pin_11);//初始化OLED屏幕
    HMC5983_calibration();//进行校准磁力计
    while (1) {
        HMC5983_Get_Data(&HMCs5983);
        printf("AID:%x,BID%x\n",HMC5983_RegA_ID(),HMC5983_RegB_ID());//打印出角度
        printf("temp%.2f,angle%.2f,x%d,y%d,z%d\n\n",HMC5983_Get_temp(),HMC5983_Get_Angle(),HMCs5983.XMag,HMCs5983.YMag,HMCs5983.ZMag);//打印出各个值
        //如果使用的是OLED请打开注释
        // OLED_Clear();
        // OLED_Printf(0,0,6,"AID:%x",HMC5983_RegA_ID());//如果读出0或255说明你没和HMC5983通信上，请检查线路连接
        // OLED_Printf(0,8,6,"x:%d",HMCs5983.XMag);
        // OLED_Printf(0,16,6,"y:%d",HMCs5983.YMag);
        // OLED_Printf(0,24,6,"z:%d",HMCs5983.ZMag);
        // OLED_Printf(0,32,6,"z:%.2f",HMC5983_Get_Angle());
        // OLED_Update();

        Delay_ms(10);
    }
}
